package com.dux.spbtservice.domin;

import javax.persistence.*;
import java.util.Objects;
import java.util.Set;

/**
 * Title: Role <br>
 * Description: Role <br>
 * Date: 2018年10月22日
 *
 * @author 王东旭
 * @version 1.0.0
 * @since jdk8
 */

@Entity
@Table(name = "role")
@NamedEntityGraph(name = "role.perms",attributeNodes = {@NamedAttributeNode(value = "perms")})
public class Role {

    @Id
    private Long id;
    private String roleName;
    private String roleDesc;
    private String creator;
    @ManyToMany(targetEntity = Perm.class)
    @JoinTable(name = "role_perm",joinColumns = {@JoinColumn(name = "roleId",referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "permId",referencedColumnName = "id")})

    private Set<Perm> perms;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    public String getRoleDesc() {
        return roleDesc;
    }

    public void setRoleDesc(String roleDesc) {
        this.roleDesc = roleDesc;
    }

    public String getCreator() {
        return creator;
    }

    public void setCreator(String creator) {
        this.creator = creator;
    }

    public Set<Perm> getPerms() {
        return perms;
    }

    public void setPerms(Set<Perm> perms) {
        this.perms = perms;
    }

    @Override
    public String toString() {
        return "Role{" +
                "id=" + id +
                ", roleName='" + roleName + '\'' +
                ", roleDesc='" + roleDesc + '\'' +
                ", creator='" + creator + '\'' +
                ", perms=" + perms +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Role)) {
            return false;
        }
        Role role = (Role) o;
        return Objects.equals(id, role.id) &&
                Objects.equals(roleName, role.roleName) &&
                Objects.equals(roleDesc, role.roleDesc) &&
                Objects.equals(creator, role.creator);
    }

    @Override
    public int hashCode() {

        return Objects.hash(id, roleName, roleDesc, creator);
    }

}
